﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChineseSchool.Models.Hethong;
using ChineseSchool.BLL;

namespace ChineseSchool
{
    public partial class ActivitiesDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblActivitiesContent.Text = LoadActivitiesContent();
                lblFacebook.Text = loadFacebook();
            }
        }

        public string LoadActivitiesContent()
        {
            string strActivities = "";
            string PageTitle = "";
            M_Activities Activities = new M_Activities();
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                int ActivitiesID = int.Parse(Request.QueryString["id"]);
                Activities = (new B_Activities()).GetByPK(ActivitiesID);
                if (Activities != null)
                {
                    strActivities += "<h1><span>" + Activities.ActivitiesTitle.ToString() + "</span></h1>";
                    strActivities += " <article class=\"alt\"> ";
                    strActivities += " <div class=\"post-excerpt\">";
                    strActivities += " <p>" + Activities.ActivitiesContent.ToString() + "</p>";
                    strActivities += " </div></article>";

                    PageTitle += "<head>";
                    PageTitle += "<title>" + Activities.ActivitiesTitle.ToString() + "</title>";
                    PageTitle += "</head>";
                }
                else
                {
                    PageTitle += "<head>";
                    PageTitle += "<title>Học tiếng trung hiệu quả</title>";
                    PageTitle += "</head>";
                }
                lblPageTitle.Text = PageTitle;
            }
            return strActivities;
        }

        public string loadFacebook()
        {
            string strFacebook = "";
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                int ActivitiesID = int.Parse(Request.QueryString["id"]);
                M_Activities M_Activities = (new B_Activities()).GetByPK(ActivitiesID);
                string Title = M_Activities.ActivitiesTitle.ToString();
                string curURL = Util.MakeLinkActivitiesDetail(ActivitiesID.ToString(), Encode.Uni2KD(Title));
                string share = "http://www.facebook.com/share.php?u=" + curURL + ";";
                if (curURL != "")
                {                    
                    strFacebook += "<div class=\"fb-comments\" data-href=\"" + curURL + "\" data-width=\"660\" data-num-posts=\"10\">";
                    strFacebook += "</div>";
                }
            }
            return strFacebook;
        }
    }
}